<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // map实现
      Array.prototype.MyMap = function (fn) {
        let res = []
        for (let i = 0; i < this.length; i++) {
          res[i] = fn(this[i], i, this)
        }
        return res
      }
      const arr = [1, 2, 3]
      console.log(arr.MyMap((item) => item + 1))
      // filter实现
      Array.prototype.Myfilter = function (fn) {
        let res = []
        for (let i = 0; i < this.length; i++) {
          if(fn(this[i], i, this)) res.push(this[i])
        }
        return res
      }
      const arr1 = [2, 4, 6, 8]
      console.log(arr1.Myfilter((item) => item>4));
    </script>
  </body>
</html>
